package com.groupfour.attendancemanagementsystem.service.impl;


import com.groupfour.attendancemanagementsystem.dao.LeaveDao;
import com.groupfour.attendancemanagementsystem.entity.DO.LeaveDO;
import com.groupfour.attendancemanagementsystem.entity.DO.LeaveOperateDO;
import com.groupfour.attendancemanagementsystem.entity.DTO.LeaveDTO;
import com.groupfour.attendancemanagementsystem.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("leaveServiceImpl")
public class LeaveServiceImpl implements LeaveService {


    private LeaveDao leaveDao;

    @Autowired
    public LeaveServiceImpl(LeaveDao leaveDao){
        this.leaveDao = leaveDao;
    }

    //查找所有请假记录实现方法
    public List<LeaveDO> findAllLeave() {
        List<LeaveDO> leaveList = leaveDao.selectAllLeave();
        return leaveList;
    }

    //通过提交时间、审批状态、原因、主题查询请假记录
    public List<LeaveDO> findLeaveByStudent(LeaveDO leave) {
        List<LeaveDO> leaveList = leaveDao.selectLeaveByStudent(leave);
        return leaveList;
    }

    //新增请假记录（学生:附件在controller写文件上传留下url）
    public int addLeave(LeaveDO leave) {
        int result = leaveDao.insertLeave(leave);
        return result;
    }

    //通过id查看假条详情（学生：详情、不通过原因）
    public LeaveDO findLeave(Integer id) {
        LeaveDO leave = leaveDao.selectLeaveById(id);
        return leave;
    }

    //通过id查看学生假条的详情然后修改
    public int updateLeaveByStudent(LeaveDO leave) {
        int result = leaveDao.updateLeaveByStudent(leave);
        return result;
    }

    //通过提交日期、院系、专业、年级、班级、学号、姓名、主题、请假原因、审批状态查询请假记录
    public List<LeaveDTO> findLeaveByTeacher(LeaveDTO leaveDTO) {
        List<LeaveDTO> leaveDTOList = leaveDao.selectLeaveByTeacher(leaveDTO);
        return leaveDTOList;
    }

    //教师通过请假记录id处理请假记录
    public int updateLeaveByTeacher(LeaveDO leave) {
        int result = leaveDao.updateLeaveByTeacher(leave);
        return result;
    }

    //管理员查看所有请假记录
    public List<LeaveDTO> findLeaveByManage() {
        List<LeaveDTO> leaveDTOList = leaveDao.selectLeaveByManage();
        return leaveDTOList;
    }

    //管理员查看所有操作记录
    public List<LeaveOperateDO> findHandleByManage() {
        List<LeaveOperateDO> leaveOperateDOList = leaveDao.selectHandleByManage();
        return leaveOperateDOList;
    }
}
